package com.eric.controller;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaCheckRole;
import cn.dev33.satoken.annotation.SaMode;
import cn.dev33.satoken.util.SaResult;
import com.eric.domain.dto.ProjectInfoDto;
import com.eric.service.IProjectInfoService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 项目信息表 前端控制器
 * </p>
 *
 * @author 新哥
 * @since 2024-03-12
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/projectInfo")
public class ProjectInfoController {
    private final IProjectInfoService projectInfoService;

    @PostMapping("/saveOne")
    @SaCheckRole(value = {"sys:coder","sys:superAdmin","sys:admin","sys:manager"},mode = SaMode.OR)
    public SaResult saveOneProject(@RequestBody ProjectInfoDto projectinfoDto){

       return projectInfoService.saveOneProjectService(projectinfoDto);
    }

    @DeleteMapping("/{id}")
    @SaCheckPermission("sys:delete")
    @SaCheckRole(value = {"sys:coder","sys:superAdmin","sys:admin","sys:manager"},mode = SaMode.OR)
    public  SaResult deleteOneProject(@PathVariable("id") Integer id){
        return projectInfoService.deleteOneProjectService(id);
    }

    @PutMapping("/modifyOne")
    @SaCheckPermission("sys:modify")
    @SaCheckRole(value = {"sys:coder","sys:superAdmin","sys:admin","sys:manager"},mode = SaMode.OR)
    public SaResult modifyOneProject(@RequestBody ProjectInfoDto projectinfoDto){
        return projectInfoService.modifyOneProject(projectinfoDto);
    }

    @GetMapping("/getAll")
    public SaResult getAllByPage(Integer cur,Integer pageSize){
        return projectInfoService.getAllService(cur,pageSize);
    }

    @GetMapping("/{id}")
    public SaResult getOneById(@PathVariable("id")Integer id){
        return projectInfoService.getOneById(id);
    }

    @GetMapping("/getByName")
    public SaResult getByName(String name,Integer pageCount,Integer pageSize){
        return projectInfoService.getByNameService(name,pageCount,pageSize);
    }

    @GetMapping("/getByContact")
    public SaResult getByContact(String contact,Integer pageCount,Integer pageSize){
        return projectInfoService.getByContactService(contact,pageCount,pageSize);
    }

    @GetMapping("/getByAddress")
    public SaResult getByAddress(String address,Integer pageCount,Integer pageSize){
        return projectInfoService.getByAddressService(address,pageCount,pageSize);
    }
}
